import 'package:love_app/common/su.dart';
import 'package:love_app/common/su_dio.dart';
import 'package:love_app/config/path_url.dart';
import 'package:love_app/enum/responst_status.dart';
import 'package:love_app/model/invite_info_model.dart';
import 'package:love_app/model/response_model.dart';
import 'package:love_app/model/user_info_model.dart';
import 'package:love_app/service/base_api.dart';

class UserInfoApi extends BaseApi {

  // 通过token获取用户信息并返回一个UserInfoModel
  Future<UserInfoModel> getUserInfo(String token) async {
    String path = PathUrl.getUserInfo;

    Map headers = {
      'X-Auth-Token': token,
    };
    ResponseModel responseModel = await SuDio().getRequest(path, headersMap: headers);
    if(responseModel.status == ResponseStatusType.success){
      UserInfoModel userInfoModel = UserInfoModel.fromJson(responseModel.toJsonModel);
      return userInfoModel; 
    }
    return null;
  }

  // 通过token获取用户信息并返回一个UserInfoModel
  Future<Map<String, dynamic>> getUserInfoData(String token) async {
    String path = PathUrl.getUserInfo;

    Map headers = {
      'X-Auth-Token': token,
    };
    ResponseModel responseModel = await SuDio().getRequest(path, headersMap: headers);
    if(responseModel.status == ResponseStatusType.success){
      return responseModel.toJsonModel;
    }
    return null;
  }

  Future<InviteInfoModel> invitationUserInfo(String token, String userCode) async {
    String path = PathUrl.getInviteInfo + "/token/$userCode";
    Map headers = {
      'X-Auth-Token': token,
    };
    ResponseModel responseModel = await SuDio().getRequest(path, headersMap: headers);
    InviteInfoModel model = InviteInfoModel.fromJson(responseModel.toJsonModel);
    return model;
  }
}
